package com.example.mywechat;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import java.util.List;
import java.util.Map;

public class adpter extends RecyclerView.Adapter<adpter.myviewholder> {

    private List<Map<String,Object>> list;
    private Context context;
    private View inflater;
    public adpter(Context context, List<Map<String,Object>> list) {
        this.list=list;
        this.context=context;
    }

    @Override
    public adpter.myviewholder onCreateViewHolder(ViewGroup parent, int viewType) {
        inflater = LayoutInflater.from(context).inflate(R.layout.item_pyq,parent,false);
        myviewholder mvh=new myviewholder(inflater);
        return  mvh;
    }

    @Override
    public void onBindViewHolder(adpter.myviewholder holder, int position) {
        holder.pyq_name.setText(list.get(position).get("name").toString());
        holder.pyq_text.setText(list.get(position).get("text").toString());

        holder.pyq_tou.setImageResource((int)list.get(position).get("tou"));
        holder.pyq_img1.setImageResource((int)list.get(position).get("img1"));
        holder.pyq_img2.setImageResource((int)list.get(position).get("img2"));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    //内部类，绑定控件
    class myviewholder extends RecyclerView.ViewHolder{
        ImageView pyq_tou;
        TextView pyq_name;
        TextView pyq_text;
        ImageView pyq_img1;
        ImageView pyq_img2;
        public myviewholder(View itemView) {
            super(itemView);
            pyq_tou=itemView.findViewById(R.id.pyq_tou);
            pyq_name=itemView.findViewById(R.id.pyq_name);
            pyq_text=itemView.findViewById(R.id.pyq_text);
            pyq_img1=itemView.findViewById(R.id.pyq_img1);
            pyq_img2=itemView.findViewById(R.id.pyq_img2);
        }
    }
}
